set -e

# 编译二进制可执行文件
make
python monitor.py hbm "./bin/hbm"
python monitor.py d2h "./bin/d2h"
python monitor.py h2d "./bin/h2d"
python monitor.py hccl_allreduce "./bin/hccl_allreduce"
python monitor.py gemm "python ./src/gemm.py"

export LD_LIBRARY_PATH=$(pwd)/src/cube-core/out/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=$(pwd)/src/cube-core/out/lib64:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=$(pwd)/src/vector-core/out/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=$(pwd)/src/vector-core/out/lib64:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/usr/local/Ascend/ascend-toolkit/latest/lib64:$LD_LIBRARY_PATH

# 编译VectorCore
rm -rf ./output && rm -rf ./input
cd src/vector-core && bash run.sh -r npu -v Ascend910B1 -b Release && cd -
cp -r src/vector-core/output ./output
cp -r src/vector-core/input ./input

# 910B1有50个Vector核
python monitor.py vector-core-1  "src/vector-core/ascendc_kernels_bbit 1"
python monitor.py vector-core-2  "src/vector-core/ascendc_kernels_bbit 2"
python monitor.py vector-core-4  "src/vector-core/ascendc_kernels_bbit 4"
python monitor.py vector-core-8  "src/vector-core/ascendc_kernels_bbit 8"
python monitor.py vector-core-10 "src/vector-core/ascendc_kernels_bbit 10"
python monitor.py vector-core-20 "src/vector-core/ascendc_kernels_bbit 20"
python monitor.py vector-core-40 "src/vector-core/ascendc_kernels_bbit 40"
python monitor.py vector-core-50 "src/vector-core/ascendc_kernels_bbit 50"

# 编译CubeCore
rm -rf ./output && rm -rf ./input
cd src/cube-core && bash run.sh -r npu -v Ascend910B1 -b Release && cd -
sleep 1
cp -r src/cube-core/output ./output
cp -r src/cube-core/input ./input

# 910B1有25个Cube核
python monitor.py cube-core-1  "src/cube-core/ascendc_kernels_bbit 1"
python monitor.py cube-core-2  "src/cube-core/ascendc_kernels_bbit 2"
python monitor.py cube-core-4  "src/cube-core/ascendc_kernels_bbit 4"
python monitor.py cube-core-8  "src/cube-core/ascendc_kernels_bbit 8"
python monitor.py cube-core-10 "src/cube-core/ascendc_kernels_bbit 10"
python monitor.py cube-core-15 "src/cube-core/ascendc_kernels_bbit 15"
python monitor.py cube-core-20 "src/cube-core/ascendc_kernels_bbit 20"
python monitor.py cube-core-25 "src/cube-core/ascendc_kernels_bbit 25"

